package leesoft.hub.actions;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.MapListHandler;

import leesoft.data.databeans.ApplicationInfoItem;
import leesoft.toolbox.PropertyManager;

public class GetTemplateListAction implements IAction {

	public Map process(SessionContext ctx) {
		// TODO Auto-generated method stub
		String sql="select id,name from tap_cytemplate order by showorder";
		String driverName=PropertyManager.getInstance().getValue("datasource.driverClassName");
		String connectionString=PropertyManager.getInstance().getValue("datasource.url");
		String username=PropertyManager.getInstance().getValue("datasource.username");
		String password=PropertyManager.getInstance().getValue("datasource.password");
		
		Connection conn;
		try{
			Class.forName(driverName);
			conn=DriverManager.getConnection(connectionString,username,password);
			QueryRunner run = new QueryRunner();
			Object result=run.query(conn, sql, new MapListHandler());
			HashMap returnMap=new HashMap();
			returnMap.put("items", result);
			DbUtils.close(conn);  
			return returnMap;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}finally{
			
		}
		
	}

	public void setRequest(HttpServletRequest request) {
		// TODO Auto-generated method stub

	}

	public void setResponse(HttpServletResponse response) {
		// TODO Auto-generated method stub

	}

}
